var e, a = require("../../@babel/runtime/helpers/defineProperty"), t = require("../../model/awconfig.js"), o = require("../../utils/util.js"), i = getApp(), d = require("../../ui/dist/base/index").$Toast;

Page({
    data: (e = {
        saveImageTips: "保存方法：点击想要保存的图片，然后长按，最后点击保存图片",
        openCustomer: 0,
        customerTitle: "客服",
        adKeyHome: i.globalData.adKeyHome,
        adKeyDYDownload: i.globalData.adKeyDYDownload,
        adKeyDYVideoInfo: i.globalData.adKeyDYVideoInfo,
        adKeyDYMusic: i.globalData.adKeyDYMusic,
        adKeyUserInifo: i.globalData.adKeyUserInifo,
        adKeyKSDownload: i.globalData.adKeyKSDownload,
        adKeyAlert: i.globalData.adKeyAlert,
        adKeyMore: i.globalData.adKeyMore,
        adKeyWater: i.globalData.adKeyWater,
        adKeyImagesDetail: i.globalData.adKeyImagesDetail,
        adKeyImagesDetail2: i.globalData.adKeyImagesDetail2,
        adVideoBanner3: i.globalData.adVideoBanner3,
        adRewardedVideo2: i.globalData.adRewardedVideo2,
        adBannerType: 3,
        showImageDetailAD: 0,
        openImgDetailRewardedVideoAd: 1,
        rewardedVideoAdImgDetailTips: "需要看完视频广告，才能一键保存图片",
        data: null,
        images: [],
        header_title: "西瓜工具"
    }, a(e, "saveImageTips", "保存方法：点击想要下载的图片，然后长按保存。"), a(e, "downloadAllBtn", "看广告一键保存"), 
    a(e, "hadViewVideoAD", 0), e),
    onLoad: function(e) {
        var a = this, o = wx.getStorageSync("ImagesTemp");
        if (null != o) {
            var i = JSON.parse(o), d = i.images;
            a.setData({
                data: i,
                images: d
            });
        }
        null != e.title && wx.setNavigationBarTitle({
            title: e.title
        }), t.registerConfigCallback(function() {
            a.awconfigSuccessCallback(1);
        }, function(e) {}), a.awconfigSuccessCallback(0), 1 == a.data.openImgDetailRewardedVideoAd && a.setupVideoAD();
    },
    awconfigSuccessCallback: function(e) {
        var t, o = wx.getStorageSync("appConfig"), i = this.data.saveImageTips;
        null != o.saveImageTips && (i = o.saveImageTips);
        var d = this.data.openCustomer;
        null != o.openCustomer && (d = o.openCustomer);
        var n = this.data.customerTitle;
        null != o.customerTitle && (n = o.customerTitle);
        i = this.data.saveImageTips;
        null != o.saveImageTips && (i = o.saveImageTips);
        var l = this.data.header_title;
        null != o.header_title && (l = o.header_title);
        var s = this.data.adBannerType;
        null != o.adBannerType && (s = o.adBannerType);
        var r = this.data.showImageDetailAD;
        null != o.showImageDetailAD && (r = o.showImageDetailAD);
        var g = this.data.openImgDetailRewardedVideoAd;
        null != o.openImgDetailRewardedVideoAd && (g = o.openImgDetailRewardedVideoAd);
        var c = this.data.rewardedVideoAdImgDetailTips;
        null != o.rewardedVideoAdImgDetailTips && (c = o.rewardedVideoAdImgDetailTips), 
        this.setData((a(t = {
            saveImageTips: i,
            openCustomer: d,
            customerTitle: n
        }, "saveImageTips", i), a(t, "header_title", l), a(t, "adBannerType", s), a(t, "showImageDetailAD", r), 
        a(t, "openImgDetailRewardedVideoAd", g), a(t, "rewardedVideoAdImgDetailTips", c), 
        t));
    },
    setupVideoAD: function() {
        var e = this, a = i.globalData.systemInfo.SDKVersion;
        if (!(o.compareVersion(a, "2.6.0") < 0)) {
            var t = wx.createRewardedVideoAd({
                adUnitId: e.data.adRewardedVideo2
            });
            t.onLoad(function() {
                e.setData({
                    videoADLoaded: !0
                });
            }), t.onError(function(a) {
                console.log(a), e.setData({
                    videoADLoaded: !1
                });
            }), t.onClose(function(a) {
                a && a.isEnded || void 0 === a ? (o.setExpiredTimeStamp("ExpiredTime"), d({
                    content: "看广告成功",
                    type: "warning",
                    duration: "5",
                    mask: !1
                }), e.setData({
                    hadViewVideoAD: 1
                }), e.downloadImage(e.data.images, 0)) : d({
                    content: "没有看完广告，看完广告才能一键保存",
                    type: "warning",
                    duration: "5",
                    mask: !1
                });
            }), e.setData({
                rewardedVideoAd: t
            });
        }
    },
    showRewardedVideoAdTips: function() {
        var e = this;
        wx.showModal({
            title: "提示",
            confirmText: "看广告",
            cancelText: "取消",
            content: e.data.rewardedVideoAdImgDetailTips,
            success: function(a) {
                a.confirm ? e.showRewardedVideoAd() : a.cancel && console.log("用户点击取消");
            }
        });
    },
    showRewardedVideoAd: function() {
        var e = this.data.rewardedVideoAd;
        e.show().catch(function(a) {
            e.load().then(function() {
                return e.show();
            });
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: "免费快首、抖因、火杉短视频去水印下载",
            path: "/pages/imageDetail/imageDetail?isShare=1",
            success: function(e) {
                console.log("分享成功"), o.setExpiredTimeStamp("ExpiredTime");
            },
            fail: function(e) {}
        };
    },
    tapImage: function(e) {
        var a = e.currentTarget.dataset.currentItem;
        console.log(a);
        var t = this.data.images;
        null != t && 0 != t.length && wx.previewImage({
            urls: t,
            current: a
        });
    },
    bindNormalSave: function(e) {
        wx.showModal({
            title: "普通保存",
            content: this.data.saveImageTips,
            showCancel: !1
        });
    },
    bindSaveAll: function(e) {
        var a = this.data.images;
        null != a && 0 != a.length ? 1 == this.data.openImgDetailRewardedVideoAd && this.data.videoADLoaded && 0 == this.data.hadViewVideoAD ? this.showRewardedVideoAd() : this.downloadImage(a, 0) : wx.showToast({
            title: "没有图片"
        });
    },
    downloadImage: function(e, a) {
        console.log("downloadImage");
        var t = this, o = e[a];
        if (a >= e.length) return wx.hideLoading(), void wx.showToast({
            title: "保存成功"
        });
        var i = "下载中：" + (a += 1).toString() + "/" + e.length.toString();
        console.log(i), wx.showLoading({
            title: i
        }), t.downloadAndSaveImage(o, function() {
            t.downloadImage(e, a);
        }, function() {
            t.downloadImage(e, a);
        });
    },
    downloadAndSaveImage: function(e, a, t) {
        var i = this.getHost(1) + "pksri?s=temp.jpg", d = {
            ssu: e
        };
        this.downloadTask = wx.downloadFile({
            url: i,
            header: o.buildHeader(d),
            success: function(e) {
                console.log(e.tempFilePath), wx.saveImageToPhotosAlbum({
                    filePath: e.tempFilePath,
                    success: function(e) {
                        a();
                    },
                    fail: function(e) {
                        console.log(e), t();
                    }
                });
            },
            fail: function(e) {
                t();
            }
        });
    },
    getHost: function(e) {
        var a = wx.getStorageSync("appConfig"), t = "https://d2.fccabc.com/";
        return null != a && a.hostimg && (t = a.hostimg), t;
    }
});